<?php
require_once("lib/db_connection.php");
require_once('phpmailer/config.php');
require_once('phpmailer/MailClass.inc');

$auto_id = $_GET['acct_id'];
$password = $_GET['password'];

//QUERY ACCOUNT EMAIL/USERNAME AND COMPANY NAME
$query_select_account = "SELECT username, company_name, company_id FROM accounts_tbl WHERE auto_id='".$auto_id."'";
$result_select_account = mysql_query($query_select_account) or die("SELECT ACCOUNT ".mysql_error());
$row_select_account = mysql_fetch_array($result_select_account);

$username = $row_select_account['username'];
$company_name = $row_select_account['company_name'];
$company_id = $row_select_account['company_id'];

//SET EXPIRATION DATE
$date = date("Y-m-d");
$newdate = strtotime ( '+2 month' , strtotime ( $date ) ) ;
$newdate = date ( 'Y-m-j' , $newdate );
$query_up_exp = "UPDATE company_tbl SET expiration_date='".$newdate."' WHERE company_id='".$company_id."'";
mysql_query($query_up_exp) or die("UPDATE ".mysql_error());

//LOGIN LINK
$login_link = "http://www.journeytech.com.ph/amps/login.php?param1=".base64_encode($password)."&param2=".base64_encode($username);

//EMAIL FUNCTION
$mailer = new FreakMailer();
$mailer->AddReplyTo('no-reply@journeytech.com.ph',"AMPS Journeytech");
$mailer->Subject = 'AMPS Account Activation';
$mailer->IsHTML(true);
$mailer->Body =
"Good Day!<br/><br/>
Your registration has been activated.<br/><br/>
Please click on this link to access your account&nbsp;<a href='".$login_link."' target='_blank'>".$login_link."</a><br/><br/>
Username: ".$username."<br/>
Password: ".$password."<br/><br/>
Try it FREE for 2 months.<br/><br/>
Thank You.<br/>
AMPS Account Registration System<br/><br/><br/><br/>
For any inquiries about AMPS please call at 8528410."
;
$mailer->AltBody = "AMPS Login Information: Username: ".$username." Password: ".$password." ";
$mailer->AddAddress($username, $company_name);
$mailer->Send();
/*if(!$mailer->Send())
{
    echo 'There was a problem sending this mail!';
}
else
{
    echo 'Mail sent!';
}*/
$mailer->ClearAddresses();
$mailer->ClearAttachments();

//ACITVATE ACCOUNT AND SET PASSWORD
$query_up_acct = "UPDATE accounts_tbl SET approval='1', password='".sha1($password)."', activate_date='".date('Y-m-d')."' WHERE auto_id='".$auto_id."'";
mysql_query($query_up_acct) or die("UPDATE ACCOUNT ".mysql_error());



?>